from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey,GenericRelation
from django.contrib.contenttypes.models import ContentType
# Create your models here.



class UserInfo(models.Model):

    username = models.CharField(max_length=32,verbose_name="用户名")
    password = models.CharField(max_length=32,verbose_name="密码")
    user_img = models.CharField(max_length=64, verbose_name='用户头像')
    mobile = models.IntegerField(verbose_name='手机号码')


class Token(models.Model):

    user = models.OneToOneField(to="UserInfo")
    token_key = models.CharField(max_length=256,verbose_name='token值')
    token_date = models.FloatField(verbose_name='token开始时间')
    expire_date = models.FloatField(verbose_name='token到期时间')


class CourseClassify(models.Model):

    title = models.CharField(max_length=32,verbose_name="课程分类")

    def __str__(self):
        return self.title


class Course(models.Model):

    title = models.CharField(max_length=64,verbose_name='课程')
    course_classify = models.ForeignKey(to="CourseClassify")
    price = models.ForeignKey(to="CoursePrice")
    course_img = models.CharField(max_length=256,verbose_name='课程图片')

    course_level_choices = (
        (1,'初级'),
        (2,'中级'),
        (3,'高级'),
    )
    popularity = models.IntegerField(verbose_name="学习人气")
    course_level = models.IntegerField(choices=course_level_choices,default=1,verbose_name="课程等级")
    course_type_choices = (
        (1,'免费课'),
        (2,'轻课'),
        (3,'学位课'),
    )
    course_type = models.IntegerField(choices=course_type_choices,default=1,verbose_name='课程类型')
    teacher = models.ManyToManyField(to='Teacher')

    def __str__(self):
        return self.title


class CoursePrice(models.Model):

    price_type_choices = (
        (1,None),
        (2,"限时免费"),
        (3,"限时折扣"),
    )
    price_type = models.IntegerField(choices=price_type_choices,default=1,verbose_name="价格类型")
    cost_price = models.FloatField(verbose_name="原价")
    now_price = models.FloatField(verbose_name="现价")


class CourseDetail(models.Model):

    course = models.OneToOneField(to='Course')
    course_hour = models.IntegerField(verbose_name="课时")
    hour = models.PositiveIntegerField(verbose_name="时长")
    entrance_requirements = models.CharField(max_length=64,null=True,blank=True,verbose_name="入学条件")
    promotion_end_date = models.DateTimeField(verbose_name="推广到期日期")
    content = models.TextField(verbose_name="图片内容")


class CourseCategory(models.Model):
    course = models.ForeignKey(to="Course",related_name='category')
    category = models.CharField(max_length=64,verbose_name="课程大类")

    def __str__(self):
        return self.category

class CourseSubCategory(models.Model):

    category = models.ForeignKey(to="CourseCategory",related_name='subcategory')
    is_free = models.BooleanField(default=False)
    title = models.CharField(max_length=64, unique=True,verbose_name="课程小类")
    def __str__(self):
        return self.title

class Teacher(models.Model):

    name = models.CharField(max_length=32,verbose_name='教师名称')
    teacher_introduce = models.TextField(verbose_name='教师介绍',null=True,blank=True)
    teacher_position = models.CharField(max_length=128,verbose_name='教师签名',null=True,blank=True)
    teacher_type_choices = (
        (1,"讲师"),
        (2,"导师"),
    )
    teacher_type = models.IntegerField(choices=teacher_type_choices,default=1,verbose_name="教师类型")
    teacher_img = models.CharField(max_length=128,verbose_name="教师图像",null=True,blank=True)

    def __str__(self):
        return self.name